
/*
  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is back: Brain Aided Coding Kit. 
  
  The Initial Developer of the Original Code is
  Zwetan Kjukov <zwetan@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2007
  the Initial Developer. All Rights Reserved.
  
  Contributor(s):
*/

/* note:
   some small utils
*/

#include "src/RGB.as"
#include "src/colors.as"
#include "src/Visual.as"
#include "src/Rect.as"
#include "src/BACK.as"
#include "src/console.as"

/* note: LiquidScreen
   A liquid screen is a UI that expand on the full width and height
   of its container window.
   
   To obtain this effect you need to thing:
   1) tell flash to not scale
   (code)
    Stage.align = "TL";
    Stage.scaleMode = "noScale";
   (end)
   2) publish your SWF with percentage dimension
      width: 100%
      height: 100%
   
   Also to have your UI resized and/or aligned
   you need to listen on the "onResize" event of the Stage
   ex:
   (code)
   mySymbol.onResize = function()
       {
       //do some stuff
       }
   Stage.addListener( mySymbol );
   (end)
*/

Stage.align = "TL"; //could be TL for SWF < 7
Stage.scaleMode = "noScale";
console.log( "init align and scalemode" );

/* note:
   UI setting.
   
   Here I used a quick and dirty way to generate simple rectangle shape
   dynamically, don't take this code as best of breed it's just an example.
*/

Visual.mode = VisualMode.fromConstructor;

//our main background that will resize with the Stage
addChild( "Rect", "BG", new RGB( 0xCC, 0x00, 0xFF ) );
Stage.addListener( _root.BG );

//a rect on the top-left
addChild( "Rect", "squareTL", colors.black, 40, 40 );
squareTL.onResize = function()
    {
    this._x = 0;
    this._y = 0;
    }
Stage.addListener( _root.squareTL );

//a rect on the top-center
addChild( "Rect", "squareTC", colors.white, 40, 40 );
squareTC.onResize = function()
    {
    this._x = Stage.width/2 - (this._width/2);
    this._y = 0;
    }
Stage.addListener( _root.squareTC );

//a rect on the top-right
addChild( "Rect", "squareTR", colors.red, 40, 40 );
squareTR.onResize = function()
    {
    this._x = Stage.width - this._width;
    this._y = 0;
    }
Stage.addListener( _root.squareTR );

//a rect on the left
addChild( "Rect", "squareL", colors.green, 40, 40 );
squareL.onResize = function()
    {
    this._x = 0;
    this._y = Stage.height/2 - (this._height/2);
    }
Stage.addListener( _root.squareL );

//a rect on the right
addChild( "Rect", "squareR", colors.blue, 40, 40 );
squareR.onResize = function()
    {
    this._x = Stage.width - this._width;
    this._y = Stage.height/2 - (this._height/2);
    }
Stage.addListener( _root.squareR );

//a rect on the bottom-left
addChild( "Rect", "squareBL", colors.yellow, 40, 40 );
squareBL.onResize = function()
    {
    this._x = 0;
    this._y = Stage.height - this._height;
    }
Stage.addListener( _root.squareBL );

//a rect on the bottom-center
addChild( "Rect", "squareBC", colors.cyan, 40, 40 );
squareBC.onResize = function()
    {
    this._x = Stage.width/2 - (this._width/2);
    this._y = Stage.height - this._height;
    }
Stage.addListener( _root.squareBC );

//a rect on the bottom-right
addChild( "Rect", "squareBR", colors.pink, 40, 40 );
squareBR.onResize = function()
    {
    this._x = Stage.width - this._width;
    this._y = Stage.height - this._height;
    }
Stage.addListener( _root.squareBR );


//a debug text on the middle
_root.createTextField( "debug", 666, 0, 0, 30, 17 );
_root.debug.background = true;
_root.debug.wordWrap   = false;
_root.debug.autoSize   = true;

debug.onResize = function()
    {
    //this.text = "W:" + Stage.width + ", H:" + Stage.height;
    this.text = "W:" + Stage.width + ", H:" + Stage.height +" ( EI: " + flash.external.ExternalInterface.available +" )";
    console.warn( "W:" + Stage.width + ", H:" + Stage.height );
    //we align it to the middle
    this._x = Stage.width/2 - (this._width/2);
    this._y = Stage.height/2 - (this._height/2);
    }

Stage.addListener( _root.debug );

//add the BACK logo aligned on the middle
Visual.mode = VisualMode.fromLibrary;

addChild( "BACK", "logo" );
logo.onResize = function()
    {
    //we align it to the middle, we decall to have it over the debug
    this._x = Stage.width/2 - (this._width/2);
    this._y = Stage.height/2 - (this._height) - (10);
    }

Stage.addListener( _root.logo );

//init
squareTL.onResize();
squareTC.onResize();
squareTR.onResize();
squareL.onResize();
squareR.onResize();
squareBL.onResize();
squareBC.onResize();
squareBR.onResize();
debug.onResize();
logo.onResize();
console.info( "general onResize()" );

